package com.library.uiframework.utils;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.StringRes;
import android.widget.Toast;

public class MToast {
	private static MToast instance;
	Toast mToast;
	
	
	Handler mHandler = new Handler() {
		public void handleMessage(Message msg) {
            if(msg.what == 1){
                String messString = (String)msg.obj;
                mToast.setText(messString);
            }else {
                int resId = (Integer) msg.obj;
                mToast.setText(resId);
            }
			mToast.show();
		}
	};

    public void setText(@StringRes int strRes) {
        mHandler.obtainMessage(2, strRes).sendToTarget();
    }

	public void setText(String mess) {
		mHandler.obtainMessage(1, mess).sendToTarget();
	}
	
	public static MToast getInstance() {
		if(instance == null) {
			instance = new MToast();
		}
		return instance;
	}
	
	private MToast() {
			
	}
	
	public void init(Context context) {
		if(mToast == null) {
			mToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);//new Toast(context);
		}
	}
	
}
